home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / WarriorsProgress.sit / Warrior’s Progress / source code / Source / CompileStatistics.cp next >
Text File  |  1997-06-28  |  2KB  |  76 lines

  1. // CompileStatistics.cp
  2.  
  3. #ifndef CompileStatistics_h
  4. #include "CompileStatistics.h"
  5. #endif
  6.  
  7. CompileStatistics::CompileStatistics()
  8.   : lines( 0 ),
  9.      files( 0 ),
  10.      lastLookup( 0 )
  11.   {
  12.   }
  13.  
  14. CompileStatistics::~CompileStatistics()
  15.   {
  16.     while ( !tree.IsEmpty() )
  17.       {
  18.         FileStatistics *stat = *tree.First();
  19.         delete stat;
  20.       }
  21.   }
  22.  
  23. uint32 CompileStatistics::AverageLines() const
  24.   {
  25.     return (files == 0) ? 10000 : lines / files;
  26.   }
  27.  
  28. void CompileStatistics::AddFile( ConstPString name )
  29.   {
  30.     FileStatistics *stat = new FileStatistics( name, AverageLines() );
  31.     files++;
  32.     lines += stat->Lines();
  33.     tree.Add( stat->link );
  34.     lastLookup = stat;
  35.   }
  36.  
  37. void CompileStatistics::SetFileLines( ConstPString name, uint32 fileLines )
  38.   {
  39.     FileStatistics *stat = Lookup( name );
  40.     Assert( stat != 0 );
  41.     
  42.     lines -= stat->Lines();
  43.     lines += fileLines;
  44.     stat->SetLines( fileLines );
  45.   }
  46.  
  47. uint32 CompileStatistics::FileLines( ConstPString name ) const
  48.   {
  49.     FileStatistics *stat = Lookup( name );
  50.     return (stat == 0) ?  AverageLines() : stat->Lines();
  51.   }
  52.  
  53. bool CompileStatistics::Known( ConstPString name ) const
  54.   {
  55.     FileStatistics *stat = Lookup( name );
  56.     return stat != 0;
  57.   }
  58.  
  59. FileStatistics *CompileStatistics::Lookup( ConstPString name ) const
  60.   {
  61.     if ( lastLookup != 0 && lastLookup->Name() == name )
  62.         return lastLookup;
  63.     
  64.     const RedBlackLink<ConstPString,FileStatistics> *node = tree.Find( name );
  65.     
  66.     if ( node == 0 )
  67.         return 0;
  68.     
  69.     const_cast<FileStatistics*&>( lastLookup ) = *node;
  70.     
  71.     Assert( lastLookup->name == name );
  72.     return lastLookup;
  73.   }
  74.  
  75. #include "RedBlackLinkTree.cp"
  76.